package com.yuhs.zixing.study.design.pattern.dp001.principle.p04.liskov.substitution;

/**
 * @description 里是替换原则 001
 * @author: yuhs
 * @date 2022/3/26 下午4:02
 */
public class LiskovSubstitutionDemo001 {

    public static void main(String[] args) {
        A001 a = new A001();
        System.out.println("11-2 = " + a.function(11, 2));
        System.out.println("----------------------------");
        B001 b = new B001();
        System.out.println("11-2 = " + b.function(11, 2));

    }
}

class A001 {
    public int function(int num1, int num2) {
        return num1 - num2;
    }
}

/**
 * B类 继承 A 类
 * 增加了一个新功能：完成两个数相加，然后再加9，求和。
 */
class B001 extends A001 {
    @Override
    public int function(int num1, int num2) {
        return num1 + num2;
    }

    public int function2(int num1, int num2) {
        return function(num1, num2) + 9;
    }
}
